# @Time:2021/6/11 16:51
# @Author:5120195554王欣霏
# -*- coding = utf-8 -*-

import pygame
import actor


class Cattle(pygame.sprite.Sprite):
    def __init__(self, init_pos_x: int, init_pos_y: int):
        pygame.sprite.Sprite.__init__(self)
        self.pos_x = init_pos_x
        self.pos_y = init_pos_y
        self.walk_frames = actor.DirAction("cattle", 'walk1', "1252-7f2abf21-", 4, 8, True)
        self.width = 124
        self.height = 106
        self.step_count = 0
        self.dir = 2
        self.speed = 5
        self.is_stop = False
        self.hp = 20  # 初始值
        self.rect = pygame.Rect(self.pos_x, self.pos_y, self.width, self.height)

    def draw(self, surface: pygame.Surface, win_pos_x, win_pos_y):
        current_frame = self.walk_frames.get_curr_frame(self.dir)
        surface.blit(current_frame, (self.pos_x - win_pos_x, self.pos_y - win_pos_y))

    def Move(self):
        if not self.is_stop:
            self.step_count += 1
            if self.step_count >= 10:
                self.step_count = 0
                if self.dir == 0:
                    self.dir = 2
                elif self.dir == 2:
                    self.dir = 0
                elif self.dir == 1:
                    self.dir = 3
                elif self.dir == 3:
                    self.dir = 1
            if self.dir == 2:
                self.pos_x -= self.speed
                self.pos_y -= self.speed
            elif self.dir == 3:
                self.pos_x += self.speed
                self.pos_y -= self.speed
            elif self.dir == 0:
                self.pos_x += self.speed
                self.pos_y += self.speed
            elif self.dir == 1:
                self.pos_x -= self.speed
                self.pos_y += self.speed
